package com.hs.shirodemo2.utils;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

/**
 * @ClassName MessageSendUtil
 * @Description TODO
 * @Author 郭敖
 * @Date 2023年09月04日 15:01
 * @Version 1.0
 */
public class MessageSendUtil {
    private  static  final String  endpoint="dysmsapi.aliyuncs.com";

    private  static  final String  accessKeyId="LTAI5tEiiP1MKHyRaMkAKMYB";
    private  static  final String  accessKeySecret="v7GwsZVDt6ELBhvv54zqsIhjlGO01J";
    private  static  final String  signName="阿里云短信测试";
    private  static  final String  templateCode="SMS_154950909";

    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = endpoint;
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public  static SendSmsResponse sendMessage(String phoneNumber, String  code) throws Exception {

        com.aliyun.dysmsapi20170525.Client client = createClient(accessKeyId, accessKeySecret);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName(signName)
                .setTemplateCode(templateCode)
                .setPhoneNumbers(phoneNumber)
                .setTemplateParam("{\"code\":\""+code+"\"}");
        RuntimeOptions runtime = new RuntimeOptions();
        // 复制代码运行请自行打印 API 的返回值
        return  client.sendSmsWithOptions(sendSmsRequest, runtime);
    }
}
